#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>


void sys_err (const char *str){
	perror(str);
	exit(1);
}

void *tfn(void *arg)
{
	// son thread
	int i = (int)arg;  // qiang zhuan

	sleep(i);
	printf("---I'm %dth thread: pid = %d, tid = %lu\n",i+1,  getpid(), pthread_self());
	return NULL;
}

int main(int argc, char *argv[]){
	// main thread
	int i;
	int ret;
	
	pthread_t tid;


	printf("main: pid = %d, tid = %lu\n", getpid(), pthread_self());
	
	for (i = 0; i < 5; i++){
	        ret = pthread_create(&tid, NULL, tfn, (void *)i);  // chuan can cai yong zhi chuan di, jie zhu qiang zhuan;
	        if (ret != 0){
	        	perror("pthread_create error");
	        }
	
	}


	sleep(i);  // fang zhi zhu xian cheng xian tui chu,zi xian cheng hai wei zhi xing
	
	return 0;
}
